package com.vhuomai.store.service.impl;

import com.quanyue.auto.util.GlobalContext;
import com.vhuomai.store.entity.BaseStoreConfig;
import com.vhuomai.store.mapper.StoreConfigMapper;
import com.vhuomai.store.service.StoreConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @author harris
 */
@Service
public class StoreConfigServiceImpl implements StoreConfigService {
    
    @Autowired
    private StoreConfigMapper configMapper;
    
    @Override
    public BaseStoreConfig find() {
        return configMapper.findByMerchantNo(GlobalContext.merchantNo());
    }
    
    @Override
    public void update(BaseStoreConfig config) {
        BaseStoreConfig exist = find();
        config.setMerchantNo(GlobalContext.merchantNo());
        config.setUpdateTime(LocalDateTime.now());
        if (exist != null) {
            config.setId(exist.getId());
            configMapper.updateSelective(config);
        } else {
            config.setCreateTime(config.getUpdateTime());
            configMapper.insert(config);
        }
    }
}
